﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Lawyer.Web.Admin
{
    public partial class admin_dashboard : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            BindStatistics();
            BindArchiveList();
            BindActivityList();
            BindTodoList();
            BindPostList();

            //BindTodoList();
            ////最近完成的
            //BindLatestList();
            ////
            //BindMyTodo();
        }

        #region 前台绑定数据
        private void BindBoxData()
        {

        }
        private void BindPostList()
        {
            Lawyer.BLL.PostInfo bll = new Lawyer.BLL.PostInfo();
            List<Lawyer.Model.PostInfo> list = bll.GetModelList(" Status=0 ");
            if (list.Count > 5) {
                list = list.Take(5).ToList();
            }
            rptPostList.DataSource = list;
            rptPostList.DataBind();
        }

        #endregion


        /// <summary>
        /// 绑定所有数据的统计
        /// </summary>
        private void BindStatistics()
        {
            List<Lawyer.Model.ItemCount> list = new List<Lawyer.Model.ItemCount>();
            Lawyer.BLL.Dashboard bll = new Lawyer.BLL.Dashboard();
            int archivecount = bll.GetCount("ArchiveInfo","");
            list.Add(new Lawyer.Model.ItemCount("Case", archivecount,"orange","admin_archivelist.aspx"));
            int activitycount = bll.GetCount("ActivityInfo","");
            list.Add(new Lawyer.Model.ItemCount("Activity", activitycount, "orange", "admin_activity.aspx"));
            int customcount = bll.GetCount("CustomInfo", "");
            list.Add(new Lawyer.Model.ItemCount("Contact", customcount, "orange", "admin_customlist.aspx"));
            int filecount = bll.GetCount("FileInfo", "");
            list.Add(new Lawyer.Model.ItemCount("Resource", filecount, "orange", "admin_file.aspx"));
            int lawyercount = bll.GetCount("UserInfo", " Type=1 AND Status=0");
            list.Add(new Lawyer.Model.ItemCount("Case Worker", lawyercount, "orange", "admin_userlist.aspx"));

            rptStasticsList.DataSource = list;
            rptStasticsList.DataBind();
            
        }

        private void BindArchiveList()
        {
            List<Lawyer.Model.ItemCount> list = new List<Lawyer.Model.ItemCount>();
            Lawyer.BLL.Dashboard bll = new Lawyer.BLL.Dashboard();
            int archive0 = bll.GetCount("ArchiveInfo", " STATUS=0");
            list.Add(new Lawyer.Model.ItemCount("Pending", archive0, "red"));
            int archive1 = bll.GetCount("ArchiveInfo", " STATUS=1");
            list.Add(new Lawyer.Model.ItemCount("Assigned to me", archive1, "orange"));
            int archive2 = bll.GetCount("ArchiveInfo", " STATUS=2");
            list.Add(new Lawyer.Model.ItemCount("Ongoing", archive2, "green"));
            int archive3 = bll.GetCount("ArchiveInfo", " STATUS=3");
            list.Add(new Lawyer.Model.ItemCount("Close Approving", archive3, "red"));
            int archive4 = bll.GetCount("ArchiveInfo", " STATUS=4");
            list.Add(new Lawyer.Model.ItemCount("Closed", archive4, "blue"));

            rptArchiveList.DataSource = list;
            rptArchiveList.DataBind();

            //

            rptArchiveStaticList.DataSource = list;
            rptArchiveStaticList.DataBind();
            

        }
        private void BindActivityList()
        {
            List<Lawyer.Model.ItemCount> list = new List<Lawyer.Model.ItemCount>();
            Lawyer.BLL.Dashboard bll = new Lawyer.BLL.Dashboard();

            int count1 = bll.GetCount("ActivityInfo", " STATUS=1");
            list.Add(new Lawyer.Model.ItemCount("Pending", count1, "red"));
            int count2 = bll.GetCount("ActivityInfo", " STATUS=2");
            list.Add(new Lawyer.Model.ItemCount("Ongoing", count2, "green"));
            int count3 = bll.GetCount("ActivityInfo", " STATUS=3");
            list.Add(new Lawyer.Model.ItemCount("Closed", count3, "blue"));
            int count4 = bll.GetCount("ActivityInfo", " STATUS=4");
            list.Add(new Lawyer.Model.ItemCount("Rejected", count4, "orange"));

            rptActivity.DataSource = list;
            rptActivity.DataBind();


            rptActivityStaticList.DataSource = list;
            rptActivityStaticList.DataBind();
        }

        private void BindTodoList()
        {
            List<Lawyer.Model.ItemCount> list = new List<Lawyer.Model.ItemCount>();
            Lawyer.BLL.Dashboard bll = new Lawyer.BLL.Dashboard();
            
            list.Add(new Lawyer.Model.ItemCount("Case Pending", bll.GetCount("ArchiveInfo", " STATUS=0"), "red"));//卷宗待审核
            list.Add(new Lawyer.Model.ItemCount("Case Closed", bll.GetCount("ArchiveInfo", " STATUS=3"), "red"));//卷宗待结束审核
            list.Add(new Lawyer.Model.ItemCount("Activity Pending", bll.GetCount("ActivityInfo", " STATUS=1"), "red"));//事件待审核
            rptTodoList.DataSource = list;
            rptTodoList.DataBind();
        }
    }
}
